import { HTTP } from "./http";
import {
  config
} from '../utils/config.js'
class BaseModel extends HTTP {

  /**
   * log 操作记录api（类型/状态默认为第一个）
   * naem: 自定义标题
   * skllType：操作类型 WXAPI("小程序") VUEAPI("管理后端")
   * logType：记录类型 STUDY("学习") BEFORE("课前") AFTER("课后") REVIEW("复习")
   * logStatus：记录的状态 INFO("正常") DEBUG("异常") ERROR("错误")
   * summary：说明
   */
  log(data) {
    return this.request({
      url: 'log/submit',
      method: 'post',
      data
    })
	}
	  /**
   * 解密微信手机号
   */
	getPhoneNumber(data) {
    return this.request({
      url: 'wechat/bindMobile',
      method: 'post',
      data: data
    })
  }
 /**  
   * 微信手机号登录
   */
  auth(mobile) {
    return this.request({
      url: 'wx/auth',
      method: 'post',
      data: {'phone': mobile}
    })
  }
  authCode(mobile, areacode) {
    return this.request({
      url: 'wx/auth',
      method: 'post',
      data: {'phone': mobile, 'areacode': areacode}
    })
  }
  /**
   * 短信验证码登录
   */
  login(form) {
    return this.request({
      url: 'wx/login',
      method: 'post',
      data: form
    })
  }

  /**
   * 获取所有广告主的账户
   */
  getAllAdvertiserAvailableAmount(advertiserId) {
    return this.request({
      url: `wechat/mini/advertiser/getAllAdvertiserAmount?advertiserId=${advertiserId}`
    })
  }

  getCreditAmount(advertiserId) {
    return this.request({
      url: `wechat/mini/advertiser/credit?advertiserId=${advertiserId}`
    })
  }

  submitReturnCredit(form) {
    return this.request({
      url: 'wechat/transfer/returnCredit',
      data: form,
      method: 'post'
    })
  }

  /**
   * 转账的接口
   * @param {Z} form 
   */
  transfer(form) {
    return this.request({
      url: 'wechat/transfer/transfer',
      method: 'post',
      data: form
    })
  }

  topUp(form) {
    return this.request({
      url: 'wechat/transfer/topUp',
      method: 'post',
      data: form
    })
  }  
 //发送验证码
 sendSms(mobile) {
  return this.request({
    url: `wx/sms?mobile=${mobile}`,
  })
}

//发送验证码
logout() {
  return this.request({
    url: `wx/logout`,
  })
}

logoff() {
  return this.request({
    url: `wx/logoff`,
  })
}

//获取微信二维码
wxacode(scene, page) {
  return this.request({
    url: `wx/wxa?scene=${scene}&page=${page}`,
  })
}

// 获取广告主可用的金额
getAdvertiserAvailableAmount(advertiserId) {
  return this.request({
    url: `wechat/transfer/available/${advertiserId}`
  })
}


current(){
  return this.request({
    url: 'wx/current',
  })
}
currentUser(){
  return this.request({
    url: 'wx/user',
  })
}

validateBindMobile() {
  return this.request({
    url: 'wechat/validate'
  })
}

getAdvertiserList() {
  return this.request({
    url: 'wechat/mini/advertiser/list'
  })
}

validateCredit() {
  return this.request({
    url: 'wechat/validateCredit'
  })
}

getAdvertiserAmount(advertiserId) {
  return this.request({
    url: `wechat/mini/advertiser/availableAmount?advertiserId=${advertiserId}`
  })
}

getBankTransferList() {
  return this.request({
    url: 'wechat/mini/advertiser/transferList'
  })
}
pay(id) {
  return this.request({
    url: `wx/pay/${id}`,
  })
}

agent(){
  return this.request({
    url: 'supplyAgent/details',
  })
}

  _post(url, data) {
    return this.request({
      url: url,
      method: 'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: data
    })
  }
  _del(url, data) {
    return this.request({
      url: url,
      method: 'DELETE',
      data: data
    })
  }
  _get(url, data) {
    return this.request({
      url: url,
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: data
    })
  }

  _getapi(url, data){
    let urlApi = config.api_base_url + url, that = this
    return new Promise((resolve, reject) => {
      wx.request({
        url: urlApi,
        method: 'GET',
        header: {
            'content-type': 'application/json',
        },
        data: data,
        success: function (res) {
          resolve(res.data)
        }
      })
    })
   

  }
  
}
export {
  BaseModel
}